#include "clistview.h"

#include <QStandardItemModel>

CListView::CListView(QWidget *parent):QListView(parent)
{
     //横向流式布局核心三句代码
     this->setViewMode(QListView::IconMode);
     this->setFlow(QListView::LeftToRight);
     this->setResizeMode(QListView::Adjust);

    //禁用滚动条
     this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
     this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

    //设置每项之间的间距
    this->setSpacing(20);
    this->setStyleSheet("background:#303642;");
}

void CListView::resizeEvent(QResizeEvent* e)
{
    //调整大小的时候重新布局，并将高度设置为（最后一项的底部位置+spacing)
    this->model()->layoutChanged();
    QRect r = this->visualRect(this->model()->index(this->model()->rowCount() - 1, 0));
    this->setFixedHeight(r.y() + r.height() + this->spacing());
}
